﻿using System;
using System.Collections.Generic;
using System.Text;
using YouHP.Model.Group;
using YouHP.Utility;
using YouHP.BLL;

namespace YouHP.Pages.Group
{
    public class GroupMemberAjax : GroupBasePage
    {
        protected List<GroupUserInfo> MemberList;
        protected string PagingString;
        protected int _pageSize = 10;
        protected int _pageIndex = 1;
        protected int _pageCount = 0;
        protected int _memberCount = 0;



        protected override void ShowPage()
        {
            base.ShowPage();

            _pageIndex = RequestTools.GetQueryInt("page", 1);

            //圈子成员列表
            MemberList = GroupUserBLL.Instance.GetGroupUserListMember(GroupData.Id, _pageSize, _pageIndex, out _memberCount);
            _pageCount = Utils.GetPageCount(_memberCount, _pageSize);
            PagingString = this.GetPagingString2(_pageIndex, _pageCount, "", "javascript:getMemberList");


            StringBuilder sb = new StringBuilder();
            sb.Append("<ul>");
            foreach (GroupUserInfo info in MemberList)
            {
                string Avatar = UserBLL.Instance.GetUserInfo(info.UserId).Avatar;
                string TempUrl = "/Profile/Index.aspx?uid=" + info.Id;
                sb.Append("<li><a href=\"" + this.GetUrl(TempUrl) + "\" target=\"_blank\">");
                sb.Append("<img width=\"45px\" height=\"45px\" src=\"" + Avatar + "\" /></a><br />");
                sb.Append("<a href=\"" + this.GetUrl(TempUrl) + "\">" + info.UserName + "</a></li>");
            }
            sb.Append("</ul>");
            sb.Append("<div style=\"clear:both;\"></div>");
            sb.Append("<div class=\"pages\" style=\"padding:10px 5px;\">" + PagingString + "</div>");

            ResponseXML(sb);


        }

        private void ResponseXML(StringBuilder sb)
        {
            System.Web.HttpContext.Current.Response.Clear();
            System.Web.HttpContext.Current.Response.ContentType = "Text/html";
            System.Web.HttpContext.Current.Response.Expires = 0;

            System.Web.HttpContext.Current.Response.Write(sb.ToString());
            System.Web.HttpContext.Current.Response.End();
        }
    }
}
